package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.dao.capital.RideUseLogDao;
import com.tbit.uqbike.client.pojo.RechargeMerchant;
import com.tbit.uqbike.client.pojo.newEntity.RideUseLog;
import com.tbit.uqbike.client.service.RideUseLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author: chen
 * @Description: 订单余额支付详情
 * @Date: 创建于 19:58 2023/1/3
 */
@Service
public class RideUseLogServiceImpl implements RideUseLogService {

    @Autowired
    private RideUseLogDao rideUseLogDao;

    @Override
    public void insert(String orderNO, Integer adAccountId, Integer brandId, Integer money,
                       Integer balance, Integer type, Date date, RechargeMerchant rechargeMerchant) {
        RideUseLog rideUseLog = new RideUseLog();
        rideUseLog.setOrderNO(orderNO);
        rideUseLog.setAccountId(brandId);
        rideUseLog.setAdAccountId(adAccountId);
        rideUseLog.setAddTime(date);
        rideUseLog.setBalance(balance);
        rideUseLog.setTotalMoney(money);
        rideUseLog.setBalanceRefund(0);
        rideUseLog.setOther(money - balance);
        rideUseLog.setOtherRefund(0);
        rideUseLog.setType(type);
        if (rechargeMerchant != null) {
            rideUseLog.setRechargeOrderNO(rechargeMerchant.getOrderNO());
            rideUseLog.setPartner(rechargeMerchant.getPartner());
        }
        rideUseLogDao.insert(rideUseLog);
    }

    @Override
    public RideUseLog getByOrderNO(String orderNO) {
        return rideUseLogDao.getByOrderNO(orderNO);
    }

    @Override
    public void update(RideUseLog rideUseLog) {
        rideUseLogDao.update(rideUseLog);
    }
}
